package cn.besbing.server.service.primary;

import cn.besbing.model.entities.primary.ReportRejectInfo;
import cn.besbing.model.entities.primary.ReportRejectInfoExample;
import cn.besbing.model.mapper.primary.ReportRejectInfoMapper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportRejectInfoServiceImpl implements ReportRejectInfoMapper {

    @Autowired(required = false)
    private ReportRejectInfoMapper rejectInfoMapper;

    @Autowired(required = false)
    private CustomerSqlServiceImpl customerSqlService;

    @Override
    public long countByExample(ReportRejectInfoExample example) {
        return rejectInfoMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(ReportRejectInfoExample example) {
        return rejectInfoMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(String pkRejectInfo) {
        return rejectInfoMapper.deleteByPrimaryKey(pkRejectInfo);
    }

    @Override
    public int insert(ReportRejectInfo record) {
        return rejectInfoMapper.insert(record);
    }

    @Override
    public int insertSelective(ReportRejectInfo record) {
        return rejectInfoMapper.insertSelective(record);
    }

    @Override
    public List<ReportRejectInfo> selectByExample(ReportRejectInfoExample example) {
        return rejectInfoMapper.selectByExample(example);
    }

    @Override
    public ReportRejectInfo selectByPrimaryKey(String pkRejectInfo) {
        return rejectInfoMapper.selectByPrimaryKey(pkRejectInfo);
    }

    @Override
    public int updateByExampleSelective(ReportRejectInfo record, ReportRejectInfoExample example) {
        return rejectInfoMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(ReportRejectInfo record, ReportRejectInfoExample example) {
        return rejectInfoMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(ReportRejectInfo record) {
        return rejectInfoMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(ReportRejectInfo record) {
        return rejectInfoMapper.updateByPrimaryKey(record);
    }

    public JSONObject getTableData() {
        JSONObject jsonObject = new JSONObject();
        ReportRejectInfoExample rejectInfoExample = new ReportRejectInfoExample();
        rejectInfoExample.setOrderByClause(" task_id desc ");
        ReportRejectInfoExample.Criteria criteria = rejectInfoExample.createCriteria();
        criteria.andDef5IsNull();
        List<ReportRejectInfo>  list = selectByExample(rejectInfoExample);
        if (list.size() > 0){
            jsonObject.put("code",0);
            jsonObject.put("msg","成功");
            jsonObject.put("count",list.size());
            jsonObject.put("data", JSONArray.parseArray(JSON.toJSONString(list)));
        }else{
            jsonObject.put("code",-1);
            jsonObject.put("msg","无数据");
            jsonObject.put("count",list.size());
            jsonObject.put("data", null);
        }
        return jsonObject;
    }

    /**
     * 穿梭框，获取处理人员
     * @return
     */
    public JSONArray getHuman() {
        List<Map<String,Object>> humanList = customerSqlService.selectList("select distinct nvl(user_name,'-') value,nvl(full_name,'-') || ':' || nvl(user_name,'-') || ';' title,'true' disabled,'false' checked  from LIMS_USERS  where LIMS_USERS.USER_DISABLED = 'F' and LIMS_USERS.IS_ROLE != 'T' ");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;
        if (humanList.size() > 0){
            for (Map<String,Object> map : humanList){
                jsonObject = new JSONObject();
                jsonObject.put("value",map.get("VALUE").toString());
                jsonObject.put("title",map.get("TITLE").toString());
                //jsonObject.put("disabled",map.get("disabled".toUpperCase()).toString());
                //jsonObject.put("checked",map.get("checked".toUpperCase()).toString());
                jsonObject.put("disabled","");
                jsonObject.put("checked","");
                jsonArray.add(jsonObject);
            }
        }
        return jsonArray;
    }


    public JSONObject getTableDataByUser(String username) {
        JSONObject jsonObject = new JSONObject();
        ReportRejectInfoExample rejectInfoExample = new ReportRejectInfoExample();
        rejectInfoExample.setOrderByClause(" task_id desc ");
        ReportRejectInfoExample.Criteria criteria = rejectInfoExample.createCriteria();
        criteria.andDef5IsNull();
        criteria.andDef4Like("%" + username + "%");
        criteria.andDef3EqualTo("处理中");
        List<ReportRejectInfo>  list = selectByExample(rejectInfoExample);
        if (list.size() > 0){
            jsonObject.put("code",0);
            jsonObject.put("msg","成功");
            jsonObject.put("count",list.size());
            jsonObject.put("data", JSONArray.parseArray(JSON.toJSONString(list)));
        }else{
            jsonObject.put("code",-1);
            jsonObject.put("msg","无数据");
            jsonObject.put("count",list.size());
            jsonObject.put("data", null);
        }
        return jsonObject;
    }


}
